#pragma once

#include <QVariant>
#include <QMetaType>
#include <vector>
#include<iostream>
#include <QObject>
#include <QThread>
#include<QString>
#include "list_message.h"
#include "QDateTime"
#include <opencv2/opencv.hpp>
using namespace cv;

using namespace std;

#include <atomic>

#include "spdlog/spdlog.h"
#include "spdlog/sinks/daily_file_sink.h"
#include "spdlog/fmt/ostr.h"
extern std::shared_ptr<spdlog::logger> logger ;

#include <QTimer>

#include "function.h"

class ShowResult
{
public:
    cv::Mat m_image;
    cv::Mat m_image_draw;
    cv::Mat m_image_ai;
    int m_camera_index;
    int m_detection_index;
    bool m_detectin_result;
    bool m_defect_result;
    bool m_location_result;
    QString m_camera_name;
    QString m_messgae;
    double m_time_use ;
	uint m_frame_rate;
    int m_save_right=0;
    int m_save_wrong=0; 
    int m_save_wrong_label=0;
    int m_save_ai_ok=0;
    int m_save_ai_ng=0;
    vector<bool> m_output_result;
	int m_times;
};//<描述一个相机单次检测完后的需要输出到主界面的统计显示信息

class QtThreadProcess : public QThread
{
    Q_OBJECT
public:
    explicit QtThreadProcess(QObject* parent = nullptr);
   

public:

    vector<bool> m_vector_result;
    int m_times =1;
	QTimer*  m_timer_frame_rate = nullptr;
	std::atomic<uint64_t>  m_frame_rate = 0;
	uint64_t  m_image_index_last = 0;




    Function* m_function;


    QString m_camera_name;
    int m_station ;
    QStringList m_detection_types_name;



    vector<cv::Rect> m_vector_roi;


    QString m_image_dir = "";
    vector<QString> m_images_path;

	

    bool  m_proess_state = false ;

    bool m_only_show_state = false  ;

    int  m_plc_read;

    uint m_detection_number =1;

    bool m_BoolSaveROIWrongImage = false;

    bool m_BoolSaveROIRightImage = false;

    bool m_BoolSaveWrongImage = false;

    bool m_BoolSaveRightImage = false;

    bool m_save_label_wrong_image =false;

    bool m_save_label_right_image =false;

    uint64_t  m_camera_index = 0;//相机的序号


    double m_time_use =0;

    //uint64_t  m_image_index=0;//相机采图图像序号

	std::atomic<uint64_t> m_image_index = 0;//相机采图图像序号

    uint64_t  m_detection_index = 0;//检测序号

   //检测线程中ng和ok的个数

	std::atomic<uint64_t> m_ng0_count =0;
	std::atomic<uint64_t> m_ok0_count =0;

	std::atomic<uint64_t> m_ng1_count = 0;
	std::atomic<uint64_t> m_ok1_count = 0;

	std::atomic<uint64_t> m_ng2_count = 0;
	std::atomic<uint64_t> m_ok2_count = 0;

	//std::vector<std::atomic<uint64_t>> m_vector_result;

    ListMessgae<cv::Mat>	m_qDisplayFrameQueue;		///< 待处理显示原始图像队列（输入图像缓冲）

signals:
   void sendDetectionResult(ShowResult result);///<相机对象处理完图像后要发射的信号

   void sendShowImage(Mat image,int camera_index,int index);///<相机对象处理完图像后要发射的信号
public slots:
	virtual void run();
};


extern void callback(Mat image, void* p);



